﻿using System;

namespace Restful.Net
{
    public class AsyncResult<T> : AsyncResult
    {
        public AsyncResult(AsyncCallback asyncCallback, object state)
            : base(asyncCallback, state)
        {
        }
        public T Result
        {
            get;
            private set;
        }

        public void StartSynchronously(Func<T> func)
        {

            Exception e = null;
            try
            {
                RestContext.Current = ServiceState.Context;
                Result = func();
            }
            catch (Exception ee)
            {
                e = ee;
            }
            finally
            {
                SetAsCompletedSynchronously(e);
            }
        }
    }
}